package leetcode.LinkList;

public class removeLastKthDoubleNode {
    public static DoubleNode process(DoubleNode head,int lastKth){
        if (head == null || lastKth < 1){
            return head;
        }
        DoubleNode cur = head;
        while (cur!=null){
            lastKth--;
            cur = cur.next;
        }
        if (lastKth==0){
            head = head.next;
            head.last = null;
        }
        if (lastKth < 0){
            cur = head;
            while (++lastKth!=0){
                cur = cur.next;
            }
            DoubleNode nextNext = cur.next.next;
            cur.next = nextNext;
            if (nextNext!=null){
                nextNext.last = cur;
            }
        }
        return head;
    }
}
